<?php

/*
	This file is part of Mandragon.

    Mandragon is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Mandragon is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Mandragon.  If not, see <http://www.gnu.org/licenses/>.
*/

//MARKED FOR DELETION

class LocationPage {
				
	private $alerter;
	
	public function __construct() {
		$this->alerter = new Alerter();
	}

	/**
	 * adds extra access checks, dependent on page state
	 */
	function page_inc_check_access() {
		check_access("READ");
		check_access("ADMIN");
	}

	/**
	 * appropriate page action interpretations
	 */
	function page_inc_execute_action($action) {
		global $PAGE;
		$locationManager = new LocationManager();
		$creator = new FormCreator();
		switch($action) {
			case "add_address":
			
				$PAGE['content']['title'] = "Een adres toevoegen";
			
				if ($_POST['submitted']) {
					$id = $locationManager->add_address($_POST);
					if ($id > 0)
						die("adres #$id ingevoerd");
				}
				$PAGE['content']['form'] = $locationManager->form_address();
				break;
				
			case "edit_address":
			
				if (!$_POST['address_id']) {
					$PAGE['content']['title'] = "Adressen wijzigen";
					$inputs = array();
					$kv = $locationManager->list_address();
					$inputs[] = $creator->input_select("Adres", "address_id", $kv['keys'], $kv['values'], "kies een adres om te wijzigen", "", "document.addressform.submit()");
					$PAGE['content']['form'] = $creator->create("addressform", $inputs);
				} else {
					$PAGE['content']['title'] = "Adres #{$_POST['address_id']} wijzigen";
				
					if ($_POST['submitted']) {
						$id = $locationManager->edit_address($_POST);
						if ($id > 0)
							die("adres #$id aangepast");
					}
					$PAGE['content']['form'] = $locationManager->form_address($locationManager->fetch_address($_POST['address_id']));
				}
				break;

			default:
				$this->alerter->add_alert('onbekende actie');
				break;
		}
	}

	/**
	 * execute page logic
	 */
	function page_inc_execute() {
		global $PAGE;
		$CONTENT = array();
		
		add_action('add_address', 'url-action', 'add_address');
		add_action('edit_address', 'url-action', 'edit_address');
	}


	/**
	 * dress up page content using skin stuff
	 */
	function page_inc_dress() {
		global $PAGE;
		if ($PAGE['content']['form'])
			print_form($page, $PAGE['content']['form']);
	}
}

?>